package com.rocket;

import com.Service.rocket.ParamConfigService;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import com.alibaba.rocketmq.common.message.MessageExt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: suzr
 * @Date: 2019-6-10 15:09
 * @return:
 * @throws:
 */
@Component
public class RocketMsgListener //implements MessageListenerConcurrently {
{
    /*Logger log = LoggerFactory.getLogger(RocketMsgListener.class);
    @Resource
    private ParamConfigService paramConfigService;

    @Override
    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
        if (CollectionUtils.isEmpty(list)) {
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
        MessageExt message = list.get(0);
        log.info("接收到的消息为：" + new String(message.getBody()));
        int reConsume = message.getReconsumeTimes();
        //消息已经重试了3次，如果不需要再次消费，则返回成功
        if (reConsume == 3) {
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
        if (message.getTopic().equals(paramConfigService.feePlatTopic)) {
            String tags = message.getTags();
            switch (tags) {
                case "FeeAccountTag":
                    log.info("开户tag{}", tags);
                    break;
                default:
                    log.info("未匹配到tag{}", tags);
                    break;
            }
        }
        //消息消费成功
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }*/
}
